package com.mxy.myapplication.service;

import android.content.ComponentName;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.RemoteException;

import com.mxy.myapplication.aidl.IMyAidlInterface;

public class MyServiceConnectionOnDifferentProcess implements ServiceConnection {

  private IMyAidlInterface iMyAidlInterface;

  public IMyAidlInterface getiMyAidlInterface(){
    return this.iMyAidlInterface;
  }


  @Override
  public void onServiceConnected(ComponentName name, IBinder service) {
    System.out.println("MyServiceConnectionOnDifferentProcess   onServiceConnected");
    iMyAidlInterface = IMyAidlInterface.Stub.asInterface(service);
    try {
      System.out.println(iMyAidlInterface.getName());
    } catch (RemoteException e) {
      e.printStackTrace();
    }
  }

  //Android 系统会在与服务的连接意外中断时（例如当服务崩溃或被终止时）调用该方法。注意:当客户端取消绑定时，系统“绝对不会”调用该方法。
  @Override
  public void onServiceDisconnected(ComponentName name) {
    System.out.println("MyServiceConnectionOnDifferentProcess   onServiceDisconnected");
  }
}
